package com.developerstation.barcode.service;

import java.text.ParseException;
import java.util.Calendar;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import my.utils.DateUtil;

import org.springframework.stereotype.Service;

import com.developerstation.barcode.mapper.CkaMapper;
import com.developerstation.barcode.model.Cka;
import com.developerstation.barcode.model.CkaExample;
@Service
public class CkaServiceImpl implements CkaService {

	@Resource
	private CkaMapper ckaMapper;
	@Override
	public List<Cka> queryCkaListForLast30Days(String ck) {
		try {
			Date now = DateUtil.getDateByDateStr(DateUtil.getGiveDateFormat(new Date(), "yyyy-MM-dd"), "yyyy-MM-dd");
			Date last30days = DateUtil.addDateCount(now, Calendar.DAY_OF_MONTH, -30);
			CkaExample example = new CkaExample();
			example.createCriteria().andCkEqualTo(ck)
									.andCreateDateGreaterThanOrEqualTo(last30days);
			List<Cka> list = ckaMapper.selectByExample(example);
			return list==null?Collections.EMPTY_LIST:list;
		} catch (ParseException e) {
			throw new RuntimeException(e);
		}
	}

}
